package com.csg.ses.service.ses.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csg.ses.common.utils.CommonUtil;
import com.csg.ses.common.utils.MybatisPlusUtil;
import com.csg.ses.dao.ses.VUserInfoDao;
import com.csg.ses.entity.ses.VUserInfoEntity;
import com.csg.ses.service.ses.VUserInfoService;
import com.csg.ses.vo.common.Result;
import com.csg.ses.vo.common.ResultStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 人员选择列表
 * @author wangjun
 * @date 2020/11/16
 */
@Service
@RequiredArgsConstructor
public class VUserInfoServiceImpl extends ServiceImpl<VUserInfoDao, VUserInfoEntity> implements VUserInfoService {
    private final VUserInfoDao vUserInfoDao;

    @Override
    public Result retrieve(VUserInfoEntity user, Long current, Long size) {
        try {
            Page<VUserInfoEntity> page = MybatisPlusUtil.initPage(current, size, true);
            QueryWrapper<VUserInfoEntity> qw = new QueryWrapper();
            if (user.getOrgId() != null) {
                qw.eq("org_id", user.getOrgId());
            }
            if (!CommonUtil.isEmpty(user.getLoginCode())) {
                qw.like("login_code", user.getLoginCode());
            }
            if (!CommonUtil.isEmpty(user.getEmpName())) {
                qw.like("emp_name", user.getEmpName());
            }
            if (!CommonUtil.isEmpty(user.getOrgName())) {
                qw.like("org_name", user.getOrgName());
            }
            qw.orderByAsc("org_code", "emp_id", "login_id");
            return new Result(vUserInfoDao.retrieve(page, qw), ResultStatus.SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException();
        }
    }
}